package robotleMvc.frameworks
{
	import _Pan3D.base.Camera3D;
	import _Pan3D.base.Focus3D;
	import _Pan3D.core.MathCore;
	import _Pan3D.display3D.Display3DContainer;
	import _Pan3D.display3D.interfaces.IDisplay3DContainer;

	import _me.Config;
	import _me.Scene_data;

	import com.adobe.utils.PerspectiveMatrix3D;

	import flash.display.BitmapData;
	import flash.display3D.Context3D;
	import flash.display3D.Context3DBlendFactor;
	import flash.display3D.Context3DCompareMode;
	import flash.display3D.Context3DProgramType;

	public class GroundDisplay3DContainer extends Display3DContainer implements IDisplay3DContainer
	{
		private var context3D:Context3D;
		private var _groundHightData:BitmapData=new BitmapData(1024, 1024, false) //这1024没意义，暂写而以
		private var _grounHightMapSize:int;

		public function GroundDisplay3DContainer()
		{
			super();
		}

		public function scanningGroundHight(tempContext3D:Context3D):BitmapData
		{
			Scene_data.grounHightMapSize=512;
			Scene_data.grounHightMapScale=10;
			_grounHightMapSize=Scene_data.grounHightMapSize;
			context3D=tempContext3D;
			context3D.configureBackBuffer(_grounHightMapSize, _grounHightMapSize, 1, true);
			context3D.clear(1, 1, 1, 1); //先设置为白色的，这里要和显示阴影的着色器里相加时
			var _projMatrix:PerspectiveMatrix3D=new PerspectiveMatrix3D();
			_projMatrix.perspectiveFieldOfViewLH(0.928, 1, 0.1, 9000);
			context3D.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 0, _projMatrix, true);
			context3D.setBlendFactors(Context3DBlendFactor.ONE, Context3DBlendFactor.ZERO);
			context3D.setDepthTest(true, Context3DCompareMode.LESS);
			/*
			在这里有必要设定地型纹理大小.一般暂用1024*1024
			确定扫描角度，垂直90度。Y转为0
			复制出之前的镜头，这样当扫描完成后，不会改变到之前的 镜头
			设计镜头比列fovw，fovh 在这时是跟渲染窗口对应，为了保证基是x/y=1 的约束。
			*/
			var fous3D:Focus3D=Scene_data.focus3D.cloneFocus3D();
			fous3D.angle_x=-90;
			fous3D.angle_y=0;
			fous3D.x=0;
			fous3D.y=0;
			fous3D.z=0;
			var cam3D:Camera3D=Scene_data.cam3D.clone();
			cam3D.distance=_grounHightMapSize
			cam3D.fovw=_grounHightMapSize
			cam3D.fovh=_grounHightMapSize;
			MathCore._catch_cam(cam3D, fous3D);
			Scene_data.cam3D.cameraMatrix=cam3D.cameraMatrix;
			for (var i:int; i < _childrenList.length; i++)
			{
				_childrenList[i].updataAndScanning();
			}
			_groundHightData=new BitmapData(_grounHightMapSize, _grounHightMapSize, false) //这1024没意义，暂写而以
			context3D.drawToBitmapData(groundHightData);
			return groundHightData;
		}

		public function get groundHightData():BitmapData
		{
			return _groundHightData;
		}

	}
}
